package com.hezhi.project.module.abnormal.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hezhi.project.module.abnormal.domain.Abnormal;
import com.hezhi.project.module.abnormal.service.IAbnormalService;
import com.hezhi.framework.web.controller.BaseController;
import com.hezhi.framework.web.page.TableDataInfo;
import com.hezhi.framework.web.domain.AjaxResult;

/**
 * 进出异常记录 信息操作处理
 * 
 * @author hezhi
 * @date 2018-08-10
 */
@Controller
@RequestMapping("/module/abnormal")
public class AbnormalController extends BaseController
{
    private String prefix = "module/abnormal";
	
	@Autowired
	private IAbnormalService abnormalService;
	
	@RequiresPermissions("module:abnormal:view")
	@GetMapping()
	public String abnormal()
	{
	    return prefix + "/abnormal";
	}
	
	/**
	 * 查询进出异常记录列表
	 */
	@RequiresPermissions("module:abnormal:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Abnormal abnormal)
	{
		startPage();
		abnormal.setRemark("0");
        List<Abnormal> list = abnormalService.selectAbnormalList(abnormal);
		return getDataTable(list);
	}
	
	@GetMapping("/studentAbnormal")
	public String studentAbnormal()
	{
	    return prefix + "/studentAbnormal";
	}
	
	/**
	 * 查询学生进出记录列表
	 */
	@RequiresPermissions("module:abnormal:studentList")
	@PostMapping("/studentList")
	@ResponseBody
	public TableDataInfo studentList(Abnormal abnormal)
	{
		startPage();
		List<Map<String, Object>> list = abnormalService.selectAbnormalStudentList(abnormal);
		return getDataTable(list);
	}
	
	/**
	 * 新增进出异常记录
	 */
	@RequiresPermissions("module:abnormal:add")
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}

	/**
	 * 修改进出异常记录
	 */
	@RequiresPermissions("module:abnormal:edit")
	@GetMapping("/edit/{abnormalId}")
	public String edit(@PathVariable("abnormalId") Integer abnormalId, Model model)
	{
		Abnormal abnormal = abnormalService.selectAbnormalById(abnormalId);
		model.addAttribute("abnormal", abnormal);
	    return prefix + "/edit";
	}
	
	/**
	 * 保存进出异常记录
	 */
	@RequiresPermissions("module:abnormal:save")
	@PostMapping("/save")
	@ResponseBody
	public AjaxResult save(Abnormal abnormal)
	{
		if (abnormalService.saveAbnormal(abnormal) > 0)
		{
			return success();
		}
		return error();
	}
	
	/**
	 * 删除进出异常记录
	 */
	@RequiresPermissions("module:abnormal:remove")
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{
		int rows = abnormalService.deleteAbnormalByIds(ids);
		if (rows > 0)
        {
            return success();
        }
        return error();
	}
	
}
